<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="format-detection" content="telephone=no"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><link rel="icon" href="/images/icons/favicon-16x16.png?v=2.6.2" type="image/png" sizes="16x16"><link rel="icon" href="/images/icons/favicon-32x32.png?v=2.6.2" type="image/png" sizes="32x32"><meta name="description" content="Turtle模块绝对是吸引非专业代码开发者人员学习python入门的好工具，通过turtle几行代码的执行软件就会画出漂亮的图形，美观而且有成就感。">
<meta property="og:type" content="article">
<meta property="og:title" content="用python的Turtle绘制冰墩墩">
<meta property="og:url" content="https://kohler19.gitee.io/2022/02/09/bingdundun/index.html">
<meta property="og:site_name" content="愷龍的网络日志">
<meta property="og:description" content="Turtle模块绝对是吸引非专业代码开发者人员学习python入门的好工具，通过turtle几行代码的执行软件就会画出漂亮的图形，美观而且有成就感。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s4.ax1x.com/2022/02/09/HGDkwt.png">
<meta property="og:image" content="http://5b0988e595225.cdn.sohucs.com/images/20190917/13fe3440d01e4664b6d74e74660b4323.jpeg">
<meta property="og:image" content="https://s4.ax1x.com/2022/01/03/Tb8ZB4.png">
<meta property="article:published_time" content="2022-02-09T08:20:23.750Z">
<meta property="article:modified_time" content="2022-03-12T05:55:07.685Z">
<meta property="article:author" content="李恺龙">
<meta property="article:tag" content="python">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s4.ax1x.com/2022/02/09/HGDkwt.png"><title>用python的Turtle绘制冰墩墩 | 愷龍的网络日志</title><link ref="canonical" href="https://kohler19.gitee.io/2022/02/09/bingdundun/"><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.12.1/css/all.min.css" type="text/css"><link rel="stylesheet" href="/css/index.css?v=2.6.2"><script>var Stun = window.Stun || {};
var CONFIG = {
  root: '/',
  algolia: undefined,
  assistSearch: undefined,
  fontIcon: {"prompt":{"success":"fas fa-check-circle","info":"fas fa-arrow-circle-right","warning":"fas fa-exclamation-circle","error":"fas fa-times-circle"},"copyBtn":"fas fa-copy"},
  sidebar: {"offsetTop":"20px","tocMaxDepth":6},
  header: {"enable":true,"showOnPost":true,"scrollDownIcon":false},
  postWidget: {"endText":true},
  nightMode: {"enable":true},
  back2top: {"enable":true},
  codeblock: {"style":"default","highlight":"light","wordWrap":false},
  reward: false,
  fancybox: false,
  zoomImage: {"gapAside":"20px"},
  galleryWaterfall: undefined,
  lazyload: false,
  pjax: undefined,
  externalLink: {"icon":{"enable":true,"name":"fas fa-external-link-alt"}},
  shortcuts: undefined,
  prompt: {"copyButton":"复制","copySuccess":"复制成功","copyError":"复制失败"},
  sourcePath: {"js":"js","css":"css","images":"images"},
};

window.CONFIG = CONFIG;</script><meta name="generator" content="Hexo 5.4.0"></head><body><div class="container" id="container"><header class="header" id="header"><div class="header-inner"><nav class="header-nav header-nav--fixed"><div class="header-nav-inner"><div class="header-nav-menubtn"><i class="fas fa-bars"></i></div><div class="header-nav-menu"><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/"><span class="header-nav-menu-item__icon"><i class="fas fa-home"></i></span><span class="header-nav-menu-item__text">首页</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/archives/"><span class="header-nav-menu-item__icon"><i class="fas fa-folder-open"></i></span><span class="header-nav-menu-item__text">归档</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/分类/"><span class="header-nav-menu-item__icon"><i class="fas fa-layer-group"></i></span><span class="header-nav-menu-item__text">分类</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/标签/"><span class="header-nav-menu-item__icon"><i class="fas fa-tags"></i></span><span class="header-nav-menu-item__text">标签</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/categories/Book/"><span class="header-nav-menu-item__icon"><i class="fas fa-book"></i></span><span class="header-nav-menu-item__text">书籍</span></a></div></div><div class="header-nav-search"><span class="header-nav-search__icon"><i class="fas fa-search"></i></span><span class="header-nav-search__text">搜索</span></div><div class="header-nav-mode"><div class="mode"><div class="mode-track"><span class="mode-track-moon"></span><span class="mode-track-sun"></span></div><div class="mode-thumb"></div></div></div></div></nav><div class="header-banner"><div class="header-banner-info"><div class="header-banner-info__title">愷龍的网络日志</div><div class="header-banner-info__subtitle">每天多学一点，以后就少敲一点代码</div></div></div></div></header><main class="main" id="main"><div class="main-inner"><div class="content-wrap" id="content-wrap"><div class="content" id="content"><!-- Just used to judge whether it is an article page--><div id="is-post"></div><div class="post"><header class="post-header"><h1 class="post-title">用python的Turtle绘制冰墩墩</h1><div class="post-meta"><span class="post-meta-item post-meta-item--createtime"><span class="post-meta-item__icon"><i class="far fa-calendar-plus"></i></span><span class="post-meta-item__info">发表于</span><span class="post-meta-item__value">2022-02-09</span></span><span class="post-meta-item post-meta-item--updatetime"><span class="post-meta-item__icon"><i class="far fa-calendar-check"></i></span><span class="post-meta-item__info">更新于</span><span class="post-meta-item__value">2022-03-12</span></span></div></header><div class="post-body"><p>Turtle模块绝对是吸引非专业代码开发者人员学习python入门的好工具，通过turtle几行代码的执行软件就会画出漂亮的图形，美观而且有成就感。  </p>
<span id="more"></span>


        <h2 id="什么是Turtle？"   >
          <a href="#什么是Turtle？" class="heading-link"><i class="fas fa-link"></i></a><a href="#什么是Turtle？" class="headerlink" title="什么是Turtle？"></a>什么是Turtle？</h2>
      <p>  Turtle英译过来为乌龟，不过我们介绍的不是这种动物，而是以此命名的一个绘图软件。在python文档中介绍了Turtle本身是一款简单、易上手的绘图软件，非常适合带领孩子们进入编程的世界。该软件由Wally Feurzeig, Seymour Papert and Cynthia Solomon等在1967年使用最原始的Logo编程语言开发而成。python语言出现后，有开发者使用python对其进行了重写，变成了Python内置的一个模块。随着python语言的大热，Turtle模块也成为了python语言简单好用的一个代名词，或者说一个很好的宣讲案例。</p>
<center> 
 <img src="https://s4.ax1x.com/2022/02/09/HGDkwt.png">
</center>
在Python中，使用turtle模块的几行代码、改变几个参数就能绘出漂亮的图形，如果再增加一些参数，还能绘制出如笑脸、哆啦A梦、表情包等创意十足的图像，令人惊叹。在学着绘图时，就会逐步学习python的一些基本语法、函数、模块、类和对象等基础知识；边玩边学四字成语非常恰当的描述了玩转turtle模块的境界，也非常适宜于少儿或者初学者进入Python的世界。    

<p>绘图主要有以下几个步骤：<br>1.设置画板<br>2.设置画笔<br>3.控制海龟移动绘制图形<br>4.色彩填充   </p>

        <h2 id="下面这些是turtle库的主要函数："   >
          <a href="#下面这些是turtle库的主要函数：" class="heading-link"><i class="fas fa-link"></i></a><a href="#下面这些是turtle库的主要函数：" class="headerlink" title="下面这些是turtle库的主要函数："></a>下面这些是turtle库的主要函数：</h2>
      <figure class="highlight python"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs python">turtle.forward(distance)<br>turtle.fd(distance)<br>画笔向前移动distance距离<br><br><br>turtle.backward(distance)<br>turtle.back (distance)/ turtle.bk (distance)<br>画笔向后移动distance距离<br><br>turtle.right(degree)<br>turtle.rt(degree)<br>绘制方向向右旋转degree度<br><br>turtle.left(degree)<br> turtle.lt(degree)<br> 绘制方向向左旋转degree度<br><br>turtle.penup()     抬起画笔，之后移动画笔不绘制图片<br>turtle.pendown() 落下画笔，之后移动画笔绘制图片<br>turtle.pensize() 设置画笔宽度<br>turtle.penup()     设置画笔颜色，常用的颜色<br></code></pre></td></tr></table></div></figure>
<p>最近,2022北京冬奥会吉祥物“冰墩墩”霸屏热搜。我们尝试使用turtle库绘制冰墩墩的图像。</p>
<center>
<img src="http://5b0988e595225.cdn.sohucs.com/images/20190917/13fe3440d01e4664b6d74e74660b4323.jpeg">
</center>
下面绘制冰墩墩的图像(仅展示部分代码，公众号回复"冰墩墩"获取完整代码)：

<figure class="highlight python"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> turtle<br>turtle.setup(<span class="hljs-number">800</span>,<span class="hljs-number">600</span>)<br><span class="hljs-comment"># 速度</span><br>turtle.speed(<span class="hljs-number">10</span>)<br><span class="hljs-comment"># 左手</span><br>turtle.penup()<br>turtle.goto(<span class="hljs-number">176</span>, <span class="hljs-number">111</span>)<br>turtle.pencolor(<span class="hljs-string">&quot;lightgray&quot;</span>)<br>turtle.pensize(<span class="hljs-number">3</span>)<br>turtle.fillcolor(<span class="hljs-string">&quot;white&quot;</span>)<br>turtle.begin_fill()<br>turtle.pendown()<br>turtle.setheading(<span class="hljs-number">80</span>)<br>turtle.circle(-<span class="hljs-number">45</span>, <span class="hljs-number">210</span>)<br>turtle.circle(-<span class="hljs-number">290</span>, <span class="hljs-number">25</span>)<br>turtle.end_fill()<br><br><span class="hljs-comment"># 轮廓</span><br><span class="hljs-comment"># 头顶</span><br>turtle.penup()<br>turtle.goto(-<span class="hljs-number">73</span>, <span class="hljs-number">230</span>)<br>turtle.pencolor(<span class="hljs-string">&quot;lightgray&quot;</span>)<br>turtle.pensize(<span class="hljs-number">3</span>)<br>turtle.fillcolor(<span class="hljs-string">&quot;white&quot;</span>)<br>turtle.begin_fill()<br>turtle.pendown()<br>turtle.setheading(<span class="hljs-number">20</span>)<br>turtle.circle(-<span class="hljs-number">250</span>, <span class="hljs-number">35</span>)<br><br><span class="hljs-comment"># 右手</span><br>turtle.setheading(-<span class="hljs-number">120</span>)<br>turtle.circle(<span class="hljs-number">50</span>, <span class="hljs-number">30</span>)<br>turtle.circle(-<span class="hljs-number">35</span>, <span class="hljs-number">200</span>)<br>turtle.circle(-<span class="hljs-number">300</span>, <span class="hljs-number">23</span>)<br><span class="hljs-comment"># 右侧</span><br>turtle.setheading(<span class="hljs-number">86</span>)<br>turtle.circle(-<span class="hljs-number">300</span>, <span class="hljs-number">26</span>)<br><span class="hljs-comment"># 右耳</span><br>turtle.setheading(<span class="hljs-number">122</span>)<br>turtle.circle(-<span class="hljs-number">53</span>, <span class="hljs-number">160</span>)<br>turtle.end_fill()<br><span class="hljs-comment"># 右腿内</span><br>turtle.penup()<br>turtle.goto(-<span class="hljs-number">38</span>, -<span class="hljs-number">210</span>)<br>turtle.fillcolor(<span class="hljs-string">&quot;black&quot;</span>)<br>turtle.begin_fill()<br>turtle.pendown()<br>turtle.setheading(-<span class="hljs-number">155</span>)<br>turtle.circle(<span class="hljs-number">15</span>, <span class="hljs-number">100</span>)<br>turtle.circle(-<span class="hljs-number">10</span>, <span class="hljs-number">110</span>)<br>turtle.circle(-<span class="hljs-number">100</span>, <span class="hljs-number">30</span>)<br>turtle.circle(-<span class="hljs-number">15</span>, <span class="hljs-number">65</span>)<br>turtle.circle(-<span class="hljs-number">100</span>, <span class="hljs-number">10</span>)<br>turtle.circle(<span class="hljs-number">200</span>, <span class="hljs-number">15</span>)<br>turtle.setheading(-<span class="hljs-number">14</span>)<br>turtle.circle(-<span class="hljs-number">200</span>, <span class="hljs-number">27</span>)<br>turtle.end_fill()<br><span class="hljs-comment"># 右眼</span><br><span class="hljs-comment"># 眼圈</span><br>turtle.penup()<br>turtle.goto(-<span class="hljs-number">64</span>, <span class="hljs-number">120</span>)<br>turtle.begin_fill()<br>turtle.pendown()<br>turtle.setheading(<span class="hljs-number">40</span>)<br>turtle.circle(-<span class="hljs-number">35</span>, <span class="hljs-number">152</span>)<br>turtle.circle(-<span class="hljs-number">100</span>, <span class="hljs-number">50</span>)<br>turtle.circle(-<span class="hljs-number">35</span>, <span class="hljs-number">130</span>)<br>turtle.circle(-<span class="hljs-number">100</span>, <span class="hljs-number">50</span>)<br>turtle.end_fill()<br><span class="hljs-comment"># 左眼</span><br><span class="hljs-comment"># 眼圈</span><br>turtle.penup()<br>turtle.goto(<span class="hljs-number">51</span>, <span class="hljs-number">82</span>)<br>turtle.fillcolor(<span class="hljs-string">&quot;black&quot;</span>)<br>turtle.begin_fill()<br>turtle.pendown()<br>turtle.setheading(<span class="hljs-number">120</span>)<br>turtle.circle(-<span class="hljs-number">32</span>, <span class="hljs-number">152</span>)<br>turtle.circle(-<span class="hljs-number">100</span>, <span class="hljs-number">55</span>)<br>turtle.circle(-<span class="hljs-number">25</span>, <span class="hljs-number">120</span>)<br>turtle.circle(-<span class="hljs-number">120</span>, <span class="hljs-number">45</span>)<br>turtle.end_fill()<br><span class="hljs-comment"># 眼珠</span><br>turtle.penup()<br>turtle.goto(<span class="hljs-number">79</span>, <span class="hljs-number">60</span>)<br>turtle.fillcolor(<span class="hljs-string">&quot;white&quot;</span>)<br>turtle.begin_fill()<br>turtle.pendown()<br>turtle.setheading(<span class="hljs-number">0</span>)<br>turtle.circle(<span class="hljs-number">24</span>, <span class="hljs-number">360</span>)<br>turtle.end_fill()<br>turtle.penup()<br>turtle.goto(<span class="hljs-number">79</span>, <span class="hljs-number">64</span>)<br>turtle.pencolor(<span class="hljs-string">&quot;darkslategray&quot;</span>)<br>turtle.fillcolor(<span class="hljs-string">&quot;darkslategray&quot;</span>)<br>turtle.begin_fill()<br>turtle.pendown()<br>turtle.setheading(<span class="hljs-number">0</span>)<br>turtle.circle(<span class="hljs-number">19</span>, <span class="hljs-number">360</span>)<br>turtle.end_fill()<br>turtle.penup()<br>turtle.goto(<span class="hljs-number">79</span>, <span class="hljs-number">70</span>)<br>turtle.fillcolor(<span class="hljs-string">&quot;black&quot;</span>)<br>turtle.begin_fill()<br>turtle.pendown()<br>turtle.setheading(<span class="hljs-number">0</span>)<br>turtle.circle(<span class="hljs-number">10</span>, <span class="hljs-number">360</span>)<br>turtle.end_fill()<br>turtle.penup()<br>turtle.goto(<span class="hljs-number">79</span>, <span class="hljs-number">88</span>)<br>turtle.pencolor(<span class="hljs-string">&quot;white&quot;</span>)<br>turtle.fillcolor(<span class="hljs-string">&quot;white&quot;</span>)<br>turtle.begin_fill()<br>turtle.pendown()<br>turtle.setheading(<span class="hljs-number">0</span>)<br>turtle.circle(<span class="hljs-number">5</span>, <span class="hljs-number">360</span>)<br>turtle.end_fill()<br><br><span class="hljs-comment"># 鼻子</span><br>turtle.penup()<br>turtle.goto(<span class="hljs-number">37</span>, <span class="hljs-number">80</span>)<br>turtle.fillcolor(<span class="hljs-string">&quot;black&quot;</span>)<br>turtle.begin_fill()<br>turtle.pendown()<br>turtle.circle(-<span class="hljs-number">8</span>, <span class="hljs-number">130</span>)<br>turtle.circle(-<span class="hljs-number">22</span>, <span class="hljs-number">100</span>)<br>turtle.circle(-<span class="hljs-number">8</span>, <span class="hljs-number">130</span>)<br>turtle.end_fill()<br><br><span class="hljs-comment"># 嘴</span><br>turtle.penup()<br>turtle.goto(-<span class="hljs-number">15</span>, <span class="hljs-number">48</span>)<br>turtle.setheading(-<span class="hljs-number">36</span>)<br>turtle.begin_fill()<br>turtle.pendown()<br>turtle.circle(<span class="hljs-number">60</span>, <span class="hljs-number">70</span>)<br>turtle.setheading(-<span class="hljs-number">132</span>)<br>turtle.circle(-<span class="hljs-number">45</span>, <span class="hljs-number">100</span>)<br>turtle.end_fill()<br><span class="hljs-comment"># 爱心</span><br>turtle.penup()<br>turtle.goto(<span class="hljs-number">220</span>, <span class="hljs-number">115</span>)<br>turtle.pencolor(<span class="hljs-string">&quot;brown&quot;</span>)<br>turtle.pensize(<span class="hljs-number">1</span>)<br>turtle.fillcolor(<span class="hljs-string">&quot;brown&quot;</span>)<br>turtle.begin_fill()<br>turtle.pendown()<br>turtle.setheading(<span class="hljs-number">36</span>)<br>turtle.circle(-<span class="hljs-number">8</span>, <span class="hljs-number">180</span>)<br>turtle.circle(-<span class="hljs-number">60</span>, <span class="hljs-number">24</span>)<br>turtle.setheading(<span class="hljs-number">110</span>)<br>turtle.circle(-<span class="hljs-number">60</span>, <span class="hljs-number">24</span>)<br>turtle.circle(-<span class="hljs-number">8</span>, <span class="hljs-number">180</span>)<br>turtle.end_fill()<br><br><span class="hljs-comment"># 五环</span><br>turtle.penup()<br>turtle.goto(-<span class="hljs-number">5</span>, -<span class="hljs-number">170</span>)<br>turtle.pendown()<br>turtle.pencolor(<span class="hljs-string">&quot;blue&quot;</span>)<br>turtle.circle(<span class="hljs-number">6</span>)<br>turtle.penup()<br>turtle.goto(<span class="hljs-number">10</span>, -<span class="hljs-number">170</span>)<br>turtle.pendown()<br>turtle.pencolor(<span class="hljs-string">&quot;black&quot;</span>)<br>turtle.circle(<span class="hljs-number">6</span>)<br>turtle.penup()<br>turtle.goto(<span class="hljs-number">25</span>, -<span class="hljs-number">170</span>)<br>turtle.pendown()<br>turtle.pencolor(<span class="hljs-string">&quot;brown&quot;</span>)<br>turtle.circle(<span class="hljs-number">6</span>)<br>turtle.penup()<br>turtle.goto(<span class="hljs-number">2</span>, -<span class="hljs-number">175</span>)<br>turtle.pendown()<br>turtle.pencolor(<span class="hljs-string">&quot;lightgoldenrod&quot;</span>)<br>turtle.circle(<span class="hljs-number">6</span>)<br>turtle.penup()<br>turtle.goto(<span class="hljs-number">16</span>, -<span class="hljs-number">175</span>)<br>turtle.pendown()<br>turtle.pencolor(<span class="hljs-string">&quot;green&quot;</span>)<br>turtle.circle(<span class="hljs-number">6</span>)<br>turtle.penup()<br><br>turtle.pencolor(<span class="hljs-string">&quot;black&quot;</span>)<br>turtle.goto(-<span class="hljs-number">16</span>, -<span class="hljs-number">160</span>)<br>turtle.write(<span class="hljs-string">&quot;BEIJING 2022&quot;</span>, font=(<span class="hljs-string">&#x27;Arial&#x27;</span>, <span class="hljs-number">10</span>, <span class="hljs-string">&#x27;bold italic&#x27;</span>))<br>turtle.hideturtle()<br><br>turtle.done()<br></code></pre></td></tr></table></div></figure>

        <h2 id="最终效果："   >
          <a href="#最终效果：" class="heading-link"><i class="fas fa-link"></i></a><a href="#最终效果：" class="headerlink" title="最终效果："></a>最终效果：</h2>
      <iframe frameborder="0" src="https://v.qq.com/txp/iframe/player.html?vid=o3322icr4ax" allowFullScreen="true"></iframe>   

<p>如果您有什么问题或建议可以在下方的评论区评论，我会及时回复的。</p>
<center><font color="red">欢迎关注我的公众号，共同学习，共同提升！</font></center>
<center><font color="red">您可以通过公众号向我留言，也可以通过邮箱（lklong@88.com）联系我</font></center>
<center>
    <img src="https://s4.ax1x.com/2022/01/03/Tb8ZB4.png">
</center></div><footer class="post-footer"><div class="post-ending ending"><div class="ending__text">------ 本文结束，感谢您的阅读 ------</div></div><div class="post-copyright copyright"><div class="copyright-author"><span class="copyright-author__name">本文作者: </span><span class="copyright-author__value"><a href="https://kohler19.gitee.io">李恺龙</a></span></div><div class="copyright-link"><span class="copyright-link__name">本文链接: </span><span class="copyright-link__value"><a href="https://kohler19.gitee.io/2022/02/09/bingdundun/">https://kohler19.gitee.io/2022/02/09/bingdundun/</a></span></div><div class="copyright-notice"><span class="copyright-notice__name">版权声明: </span><span class="copyright-notice__value">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en" rel="external nofollow" target="_blank">BY-NC-SA</a> 许可协议。转载请注明出处！</span></div></div><div class="post-tags"><span class="post-tags-item"><span class="post-tags-item__icon"><i class="fas fa-tag"></i></span><a class="post-tags-item__link" href="https://kohler19.gitee.io/tags/python/">python</a></span></div><nav class="post-paginator paginator"><div class="paginator-prev"><a class="paginator-prev__link" href="/2022/03/12/Discrete-Mathematical-Structures/"><span class="paginator-prev__icon"><i class="fas fa-angle-left"></i></span><span class="paginator-prev__text">离散数学结构 第6版 英文原版+汉语版</span></a></div><div class="paginator-next"><a class="paginator-next__link" href="/2022/01/31/idea2021/"><span class="paginator-prev__text">idea2021破解使用带配置文件</span><span class="paginator-next__icon"><i class="fas fa-angle-right"></i></span></a></div></nav></footer></div></div><div class="comments" id="comments"><div id="valine-container"></div></div></div><div class="sidebar-wrap" id="sidebar-wrap"><aside class="sidebar" id="sidebar"><div class="sidebar-nav"><span class="sidebar-nav-toc current">文章目录</span><span class="sidebar-nav-ov">站点概览</span></div><section class="sidebar-toc"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AFTurtle%EF%BC%9F"><span class="toc-number">1.</span> <span class="toc-text">
          什么是Turtle？</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%8B%E9%9D%A2%E8%BF%99%E4%BA%9B%E6%98%AFturtle%E5%BA%93%E7%9A%84%E4%B8%BB%E8%A6%81%E5%87%BD%E6%95%B0%EF%BC%9A"><span class="toc-number">2.</span> <span class="toc-text">
          下面这些是turtle库的主要函数：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9C%80%E7%BB%88%E6%95%88%E6%9E%9C%EF%BC%9A"><span class="toc-number">3.</span> <span class="toc-text">
          最终效果：</span></a></li></ol></section><!-- ov = overview--><section class="sidebar-ov hide"><div class="sidebar-ov-author"><div class="sidebar-ov-author__avatar"><img class="sidebar-ov-author__avatar_img" src="https://s4.ax1x.com/2022/01/03/Tb2VW6.png" alt="avatar"></div><p class="sidebar-ov-author__text">格物致知，知行合一</p></div><div class="sidebar-ov-social"><a class="sidebar-ov-social-item" href="https://s4.ax1x.com/2022/01/03/Tb8ZB4.png" target="_blank" rel="noopener" data-popover="微信" data-popover-pos="up"><span class="sidebar-ov-social-item__icon"><i class="fab fa-weixin"></i></span></a><a class="sidebar-ov-social-item" href="mailto:lklong@88.com" target="_blank" rel="noopener" data-popover="social.Email" data-popover-pos="up"><span class="sidebar-ov-social-item__icon">lklong@88.com</span></a></div><div class="sidebar-ov-cc"><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en" target="_blank" rel="noopener" data-popover="知识共享许可协议" data-popover-pos="up"><img src="/images/cc-by-nc-sa.svg"></a></div></section><div class="sidebar-reading"><div class="sidebar-reading-info"><span class="sidebar-reading-info__text">你已阅读了 </span><span class="sidebar-reading-info__num">0</span><span class="sidebar-reading-info__perc">%</span></div><div class="sidebar-reading-line"></div></div></aside></div><div class="clearfix"></div></div></main><footer class="footer" id="footer"><div class="footer-inner"><div><span>Copyright © 2023</span><span class="footer__icon"><i class="fas fa-heart"></i></span><span>愷龍 All Rights Reserved</span></div><div><span>由 <a href="http://hexo.io/" title="Hexo" target="_blank" rel="noopener">Hexo</a> 强力驱动</span><span> v5.4.0</span><span class="footer__devider">|</span><span>主题 - <a href="https://github.com/liuyib/hexo-theme-stun/" title="Stun" target="_blank" rel="noopener">Stun</a></span><span> v2.6.2</span></div></div></footer><div class="loading-bar" id="loading-bar"><div class="loading-bar__progress"></div></div><div class="back2top" id="back2top"><span class="back2top__icon"><i class="fas fa-rocket"></i></span></div></div><div class="search-mask"></div><div class="search-popup"><span class="search-close"></span><div class="search-input"><input placeholder="搜索文章（支持多关键词，请用空格分隔）"></div><div class="search-results"></div></div><script src="https://cdn.jsdelivr.net/npm/jquery@v3.4.1/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5.2/velocity.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5.2/velocity.ui.min.js"></script><script>function initSearch() {
  var isXML = true;
  var search_path = 'search.xml';

  if (!search_path) {
    search_path = 'search.xml';
  } else if (/json$/i.test(search_path)) {
    isXML = false;
  }

  var path = '/' + search_path;
  $.ajax({
    url: path,
    dataType: isXML ? 'xml' : 'json',
    async: true,
    success: function (res) {
      var datas = isXML ? $('entry', res).map(function () {
        // 将 XML 转为 JSON
        return {
          title: $('title', this).text(),
          content: $('content', this).text(),
          url: $('url', this).text()
        };
      }).get() : res;
      var $input = $('.search-input input');
      var $result = $('.search-results');
      // 搜索对象（标题、内容）的权重，影响显示顺序
      var WEIGHT = { title: 100, content: 1 };
      var searchPost = function () {
        var searchText = $input.val().toLowerCase().trim();
        // 根据空白字符分隔关键字
        var keywords = searchText.split(/[\s]+/);
        // 搜索结果
        var matchPosts = [];

        // 有多个关键字时，将原文字整个保存下来
        if (keywords.length > 1) {
          keywords.push(searchText);
        }
        // 防止未输入字符时搜索
        if (searchText.length > 0) {
          datas.forEach(function (data) {
            var isMatch  = false;
            // 没有标题的文章使用预设的 i18n 变量代替
            var title = (data.title && data.title.trim()) || '[ 文章无标题 ]';
            var titleLower = title && title.toLowerCase();
            // 删除 HTML 标签 和 所有空白字符
            var content = data.content && data.content.replace(/<[^>]+>/g, '');
            var contentLower = content && content.toLowerCase();
            // 删除重复的 /
            var postURL = data.url && decodeURI(data.url).replace(/\/{2,}/g, '/');
            // 标题中匹配到的关键词
            var titleHitSlice = [];
            // 内容中匹配到的关键词
            var contentHitSlice = [];

            keywords.forEach(function (keyword) {
              /**
              * 获取匹配的关键词的索引
              * @param {String} keyword 要匹配的关键字
              * @param {String} text 原文字
              * @param {Boolean} caseSensitive 是否区分大小写
              * @param {Number} weight 匹配对象的权重。权重大的优先显示
              * @return {Array}
              */
              function getIndexByword (word, text, caseSensitive, weight) {
                if (!word || !text) {
                  return [];
                };

                var startIndex = 0; // 每次匹配的开始索引
                var index = -1;     // 匹配到的索引值
                var result = [];    // 匹配结果

                if (!caseSensitive) {
                  word = word.toLowerCase();
                  text = text.toLowerCase();
                }

                while((index = text.indexOf(word, startIndex)) !== -1) {
                  var hasMatch = false;
                  // 索引位置相同的关键词，保留长度较长的
                  titleHitSlice.forEach(function (hit) {
                    if (hit.index === index && hit.word.length < word.length) {
                      hit.word = word;
                      hasMatch = true;
                    }
                  });
                  startIndex = index + word.length;
                  !hasMatch && result.push({ index: index, word: word, weight: weight });
                }
                return result;
              }
              titleHitSlice = titleHitSlice.concat(getIndexByword(keyword, titleLower, false, WEIGHT.title));
              contentHitSlice = contentHitSlice.concat(getIndexByword(keyword, contentLower, false, WEIGHT.content));
            });

            var hitTitle = titleHitSlice.length;
            var hitContent = contentHitSlice.length;

            if (hitTitle > 0 || hitContent > 0) {
              isMatch = true;
            }
            if (isMatch) {
              ;[titleHitSlice, contentHitSlice].forEach(function (hit) {
                // 按照匹配文字的索引的递增顺序排序
                hit.sort(function (left, right) {
                  return left.index - right.index;
                });
              });
              /**
              * 给文本中匹配到的关键词添加标记，从而进行高亮显示
              * @param {String} text 原文本
              * @param {Array} hitSlice 匹配项的索引信息
              * @param {Number} start 开始索引
              * @param {Number} end 结束索引
              * @return {String}
              */
              function highlightKeyword (text, hitSlice, start, end) {
                if (!text || !hitSlice || !hitSlice.length) {
                  return;
                }

                var result = '';
                var startIndex = start;
                var endIndex = end;
                hitSlice.forEach(function (hit) {
                  if (hit.index < startIndex) {
                    return;
                  }

                  var hitWordEnd = hit.index + hit.word.length;
                  result += text.slice(startIndex, hit.index);
                  result += '<b>' + text.slice(hit.index, hitWordEnd) + '</b>';
                  startIndex = hitWordEnd;
                });
                result += text.slice(startIndex, endIndex);
                return result;
              }

              var postData = {};
              // 文章总的搜索权重
              var postWeight = titleHitSlice.length * WEIGHT.title + contentHitSlice.length * WEIGHT.content;
              // 标记匹配关键词后的标题
              var postTitle = highlightKeyword(title, titleHitSlice, 0, title.length) || title;
              // 标记匹配关键词后的内容
              var postContent;
              // 显示内容的长度
              var SHOW_WORD_LENGTH = 200;
              // 命中关键词前的字符显示长度
              var SHOW_WORD_FRONT_LENGTH = 20;
              var SHOW_WORD_END_LENGTH = SHOW_WORD_LENGTH - SHOW_WORD_FRONT_LENGTH;

              // 截取匹配的第一个字符，前后共 200 个字符来显示
              if (contentHitSlice.length > 0) {
                var firstIndex = contentHitSlice[0].index;
                var start = firstIndex > SHOW_WORD_FRONT_LENGTH ? firstIndex - SHOW_WORD_FRONT_LENGTH : 0;
                var end = firstIndex + SHOW_WORD_END_LENGTH;
                postContent = highlightKeyword(content, contentHitSlice, start, end);
              } else { // 未匹配到内容，直接截取前 200 个字符来显示
                postContent = content.slice(0, SHOW_WORD_LENGTH);
              }
              postData.title = postTitle;
              postData.content = postContent;
              postData.url = postURL;
              postData.weight = postWeight;
              matchPosts.push(postData);
            }
          });
        }

        var resultInnerHtml = '';
        if (matchPosts.length) {
          // 按权重递增的顺序排序，使权重大的优先显示
          matchPosts.sort(function (left, right) {
            return right.weight - left.weight;
          });
          resultInnerHtml += '<ul>';
          matchPosts.forEach(function (post) {
            resultInnerHtml += '<li><a class="search-results-title" href="' + post.url + '">';
            resultInnerHtml += post.title;
            resultInnerHtml += '</a><div class="search-results-content">';
            resultInnerHtml += post.content;
            resultInnerHtml += '</div></li>';
          });
          resultInnerHtml += '</ul>';
        } else {
          resultInnerHtml += '<div class="search-results-none"><i class="far fa-meh"></i></div>';
        }
        $result.html(resultInnerHtml);
      };
      $input.on('input', searchPost);
      $input.on('keyup', function (e) {
        if (e.keyCode === Stun.utils.codeToKeyCode('Enter')) {
          searchPost();
        }
      });
    }
  });
}

function closeSearch () {
  $('body').css({ overflow: 'auto' });
  $('.search-popup').css({ display: 'none' });
  $('.search-mask').css({ display: 'none' });
}

window.addEventListener('DOMContentLoaded', function () {
  Stun.utils.pjaxReloadLocalSearch = function () {
    $('.header-nav-search').on('click', function (e) {
      e.stopPropagation();
      $('body').css('overflow', 'hidden');
      $('.search-popup')
        .velocity('stop')
        .velocity('transition.expandIn', {
          duration: 300,
          complete: function () {
            $('.search-popup input').focus();
          }
        });
      $('.search-mask')
        .velocity('stop')
        .velocity('transition.fadeIn', {
          duration: 300
        });

      initSearch();
    });
    $('.search-mask, .search-close').on('click', function () {
      closeSearch();
    });
    $(document).on('keydown', function (e) {
      // Escape <=> 27
      if (e.keyCode === Stun.utils.codeToKeyCode('Escape')) {
        closeSearch();
      }
    });
  };

  Stun.utils.pjaxReloadLocalSearch();
}, false);

function safeOpenUrl(url) {
  var newTab = window.open();
  newTab.opener = null;
  newTab.location = url;
}

function extSearch(engine) {
  var engines = {
    google: 'https://www.google.com/search?q=',
    bing: 'https://cn.bing.com/search?q=',
    baidu: 'https://www.baidu.com/s?ie=UTF-8&wd=',
  };
  var host = window.location.host;
  var query = $('.search-input input').val().toLowerCase().trim();
  var uri = engines[engine] + query + ' site:' + host;

  if (query) {
    safeOpenUrl(uri);
  } else {
    Stun.utils.popAlert('warning', '请输入字符');
  }
}

var assistSearchList = window.CONFIG.assistSearch;

if (Array.isArray(assistSearchList)) {
  assistSearchList.forEach(function (name) {
    document.querySelector('.search-btns-item--' + name).addEventListener('click', function () {
      extSearch(name);
    }, false);
  });
}</script><script src="https://cdn.jsdelivr.net/npm/leancloud-storage@latest/dist/av-min.js"></script><script src="https://cdn.jsdelivr.net/npm/valine@latest/dist/Valine.min.js"></script><script>function loadValine () {
  var GUEST_INFO = ['nick', 'mail', 'link'];
  var guest_info = 'nick,mail,link';

  guest_info = guest_info.split(',').filter(function(item) {
    return GUEST_INFO.indexOf(item) > -1;
  });
  new Valine({
    el: '#valine-container',
    appId: 'lxsmJYFBR3TcsTpKPFWSN0HX-gzGzoHsz',
    appKey: 'lW6taHRzBHFtJeWSSzXXMAxH',
    notify: true,
    verify: true,
    placeholder: 'Just go go',
    avatar: 'mp',
    meta: guest_info,
    pageSize: '10' || 10,
    visitor: false,
    recordIP: false,
    lang: '' || 'zh-cn',
    path: window.location.pathname
  });
}

if (false) {
  loadValine();
} else {
  window.addEventListener('DOMContentLoaded', loadValine, false);
}</script><script src="/js/utils.js?v=2.6.2"></script><script src="/js/stun-boot.js?v=2.6.2"></script><script src="/js/scroll.js?v=2.6.2"></script><script src="/js/header.js?v=2.6.2"></script><script src="/js/sidebar.js?v=2.6.2"></script><script type="application/json" src="/search.xml"></script></body></html>